dcc8ad
@@ -25,9 +25,11 @@
import java.util.List;
 import javax.persistence.EntityManager;
 import javax.persistence.LockModeType;
 import javax.persistence.NoResultException;
+import javax.persistence.Parameter;
 import javax.persistence.TypedQuery;
 import javax.persistence.criteria.CriteriaBuilder;
 import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.ParameterExpression;
 import javax.persistence.criteria.Path;
 import javax.persistence.criteria.Predicate;
 import javax.persistence.criteria.Root;
@@ -272,12 +274,10 @@
public class SimpleJpaRepository<T, ID extends Serializable> implements JpaRepos
 			return Collections.emptyList();
 		}
 
-		return getQuery(new Specification<T>() {
-			public Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
-				Path<?> path = root.get(entityInformation.getIdAttribute());
-				return path.in(cb.parameter(Iterable.class, "ids"));
-			}
-		}, (Sort) null).setParameter("ids", ids).getResultList();
+		ByIdsSpecification specification = new ByIdsSpecification();
+		TypedQuery<T> query = getQuery(specification, (Sort) null);
+
+		return query.setParameter(specification.parameter, ids).getResultList();
 	}
 
 	/*
@@ -524,4 +524,29 @@
public class SimpleJpaRepository<T, ID extends Serializable> implements JpaRepos
 		LockModeType type = lockMetadataProvider == null ? null : lockMetadataProvider.getLockModeType();
 		return type == null ? query : query.setLockMode(type);
 	}
+
+	/**
+	 * Specification that gives access to the {@link Parameter} instance used to bind the ids for
+	 * {@link SimpleJpaRepository#findAll(Iterable)}. Workaround for OpenJPA not binding collections to in-clauses
+	 * correctly when using by-name binding.
+	 * 
+	 * @see https://issues.apache.org/jira/browse/OPENJPA-2018?focusedCommentId=13924055
+	 * @author Oliver Gierke
+	 */
+	@SuppressWarnings("rawtypes")
+	private final class ByIdsSpecification implements Specification<T> {
+
+		ParameterExpression<Iterable> parameter;
+
+		/*
+		 * (non-Javadoc)
+		 * @see org.springframework.data.jpa.domain.Specification#toPredicate(javax.persistence.criteria.Root, javax.persistence.criteria.CriteriaQuery, javax.persistence.criteria.CriteriaBuilder)
+		 */
+		public Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
+
+			Path<?> path = root.get(entityInformation.getIdAttribute());
+			parameter = cb.parameter(Iterable.class);
+			return path.in(parameter);
+		}
+	}
 }
